<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
     function fn(nums) {
      //去掉开始的'L'
      while (nums[0] == 'L') {
        nums = nums.slice(1)
      }
      //去掉结尾的'R'
      while (nums[nums.length - 1] == 'R') {
        nums = nums.slice(0, nums.length - 1)
      }
      //去掉'S'
      nums = nums.replaceAll('S', '')
      return nums.length
    }
    console.log(fn('RLRSLL'))
  </script>
</body>
</html>